package cn.gjxblog.modules.sys.controller;

import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.common.model.PageInfo;
import cn.gjxblog.common.model.PageRequest;
import cn.gjxblog.modules.sys.entity.SysRoleMenuEntity;
import cn.gjxblog.modules.sys.service.SysRoleMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;




/**
 * 角色与菜单对应关系
 *
 * @author guojiaxun
 * @date 2019-09-17 11:32:47
 */
@RestController
@RequestMapping("sys/sysrolemenu")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @ApiOperation("获取列表")
    public HttpResult<PageInfo> list(@RequestBody PageRequest pageRequest){
        PageInfo pageInfo = sysRoleMenuService.searchList(pageRequest);
        return HttpResult.ok(pageInfo);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("获取信息")
    public HttpResult info(@PathVariable("id") Long id){
		SysRoleMenuEntity sysRoleMenu = sysRoleMenuService.getById(id);

        return HttpResult.ok(sysRoleMenu);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存信息")
    public HttpResult save(@RequestBody SysRoleMenuEntity sysRoleMenu){
		sysRoleMenuService.save(sysRoleMenu);

        return HttpResult.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改信息")
    public HttpResult update(@RequestBody SysRoleMenuEntity sysRoleMenu){
		sysRoleMenuService.updateById(sysRoleMenu);

        return HttpResult.ok();
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    @ApiOperation("删除信息")
    public HttpResult delete(@RequestBody Long[] ids){
		sysRoleMenuService.removeByIds(Arrays.asList(ids));
        return HttpResult.ok();
    }

}
